package com.atguigu.boot.controller;

import com.atguigu.boot.entities.Customer;
import com.atguigu.boot.service.CustomerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @ClassName CustomerController
 * @Description 此类描述:
 * @Author dangchen
 * @DateTime 2022-09-15 15:22
 * @Version 1.0
 */
@RestController
@Slf4j
@RequestMapping("/customer")
@Api("customer接口")
public class CustomerController {
    @Resource
    private CustomerService customerService;

    @ApiOperation("增加一个顾客信息")
    @PostMapping("/add")
    public void add(Customer customer){
        customerService.add(customer);
    }

    @ApiOperation("删除该ID的顾客信息")
    @DeleteMapping("/{id}")
    public void delete(@PathVariable Integer id){
        customerService.delete(id);
    }

    @ApiOperation("更新该ID的顾客信息")
    @PutMapping("/{id}")
    public void update(@PathVariable Integer id, Customer customer){
        customerService.update(customer);
    }

    @ApiOperation("查找该ID的顾客信息")
    @GetMapping("/{id}")
    public Customer getCustomerById(@PathVariable Integer id){
        return customerService.getCustomerById(id);
    }

    @ApiOperation("查找所有顾客信息")
    @GetMapping("/list")
    public List<Customer> list(){
        return customerService.list();
    }
}
